<template>
	<view>
		<web-view :webview-styles="webviewStyles" :src="src" @message="postMessage"></web-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				src: '/hybrid/html/loading.html',
				webviewStyles: {
					progress: {
						color: '#FF3333'
					}
				}
			};
		},
		onLoad(option) {
			this.src = encodeURI(option.home_url.replace('|||', '&'))
		},
		methods: {
			postMessage(e) {
        uni.showLoading({
          title: '文件加载中...',
          mask: false
        });
				if(e.detail.data[0].docUrl) {
					uni.downloadFile({
					  url: e.detail.data[0].docUrl,
					  success: function (res) {
					    var filePath = res.tempFilePath;
					    uni.openDocument({
					      filePath: filePath,
                fail:function(res){
                  uni.showToast({
                    title:"文件打开失败！"
                  })
                },complete() {
                  uni.hideLoading()
                }
					    })
					  },
            fail:function(res){
              uni.showToast({
                title:"文件打开失败！"
              })
            },
            complete:function(res){
              uni.hideLoading()
            }
					})
				}
			}
		}
	}
</script>

